export const insertImgFn = function (editor, args) {
    const loop = function (value) {
        const {url, type, name, data = {}, style} = value;
        if (!url) return false;
        let attrData = '';
        if (data && Object.keys(data).length > 0) {
            for (let key in data) {
                attrData += ` data-${key}=${data[key]}`
            }
        }
        if (url === 'javascript:void(0)') {
            attrData += ' onclick="return false;"'
        } else if (typeof url === "string" && url.trim().length > 0) {
            attrData += ` href="${url}"`
        }
        let dom = `<a ${attrData} style="${style}" target="_blank">${name || url}</a>&nbsp;`
        if (/^image\/(\w){1,}$/.test(type)) {
            dom = `<img ${attrData} style="${style}" src="${url || 'javascript:void(0)'}" style="max-width:100%"/>`
        }
        return dom;
    }
    if (Array.isArray(args)) {
        const list = args.map(value => loop(value)).filter(value => value !== false);
        if (list.length === 0) return;
        editor.cmd.do('insertHTML', list.join(''))
    } else if (args.url) {
        editor.cmd.do('insertHTML', loop(args))
    }
}
